package Work03.Task02;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

/**
 * @Author: lu
 * @Date: 2021/9/1 20:59
 * @Description:
 */
public class WorkerTest {
    public static void main(String[] args) {
        List<Worker> lt = new ArrayList<>();
        lt.add(new Worker("凤姐",18,20000));
        lt.add(new Worker("欧阳锋",60,8000));
        lt.add(new Worker("刘德华",40,30000));
        System.out.println(Arrays.toString(lt.toArray()));
        lt.add(1,new Worker("张柏芝",35,3300));
        lt.remove(new Worker("刘德华",40,30000));
        System.out.println(Arrays.toString(lt.toArray()));
        for (Worker w:lt) {
            System.out.println(w.toString());
        }
        //foreach
        for (Worker w : lt) {
            w.work();
        }
        //迭代器
        Iterator iterator = lt.iterator();
        while (iterator.hasNext()){
            Worker w = (Worker) iterator.next();
            w.work();
        }

    }
}
